//
//  HomecountViewController.m
//  ChatDemo-UI2.0
//
//  Created by syun on 16/4/7.
//  Copyright © 2016年 syun. All rights reserved.
//

//1、请求未读名单获取数组，循环加入一个check字段，默认值为1选中，0未选中；2、第一次进入页面默认选中全部，设置flag值为默认值为yes,点击全选按钮flag=!flag.
#import "HomecountViewController.h"
#import "NoticeCountTableViewCell.h"
#import "DetailHvkViewController.h"
#import "noReadListViewCell.h"
#import "noReadModel.h"
@interface HomecountViewController ()<UIAlertViewDelegate>

{
    UIButton *allSelectBtn;
    NSMutableArray *dataArray;
    UILabel *allCountLabel;
    UILabel *weiduCount;
    NSDictionary *Infodict;
    NSString *stateQuanXuan;//0是取消 1是全选
    NSMutableArray *xuanzhongArray;
    int count;
    NSString *allNum;
    NSString *noreadNum;
    UIButton *sureBtn;
    UIView *noworkView;
    UIView *allreadworkView;
    BOOL isSend;//YES为发短信
    UIImageView *sendMesImage;//发短信选择按钮
    UILabel *sendLale;//短信标志
    UIButton *sendMes;//选择是否发送短信响应按钮
    
    BOOL flag;//是否全选
    
    UIButton *readBtn;
    UIButton *noreadBtn;
    UIButton *finshBtn;
    
    //已读
    NSDictionary *rInfodict;
    NSString *readNum;
    NSMutableArray *rdataArray;//已读名单
    
    int isread;//1是已读，2 未读,3 已完成
    
    NSString *finshNum;//已完成
    NSDictionary *finshInfoDic;
    NSMutableArray *finshArray;
    
    UIView *noFinshView;
    
    EmptyStateView *noemptyView;//未读空状态
    EmptyStateView *reademptyView;//已读空状态
    EmptyStateView *finishemptyView;//已完成空状态

}

@property (nonatomic,strong) UIScrollView *scroll;
@property (nonatomic,strong) UITableView *myTableView;
@property (nonatomic,strong) UITableView *myreadTableView;
@property (nonatomic,strong) UITableView *myFinshTableView;
@end

@implementation HomecountViewController

- (UIScrollView *)scroll
{
    if (_scroll==nil) {
        _scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 168+64, SCREENWIDTH*3, SCREENHEIGH-168-64)];
        _scroll.delegate=self;
    }
    return _scroll;
}
- (UITableView *)myTableView
{
    if (_myTableView==nil) {
        
        _myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, _scroll.frame.size.height-110)  style:UITableViewStylePlain];
        _myTableView.delegate=self;
        _myTableView.dataSource=self;
        _myTableView.showsVerticalScrollIndicator=NO;
        _myTableView.bounces=NO;
        _myTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _myTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    }
    return _myTableView;
}

- (UITableView *)myreadTableView
{
    if (_myreadTableView==nil) {
        
        _myreadTableView=[[UITableView alloc]initWithFrame:CGRectMake(SCREENWIDTH, 0, SCREENWIDTH, _scroll.frame.size.height)style:UITableViewStylePlain];
        _myreadTableView.delegate=self;
        _myreadTableView.dataSource=self;
        _myreadTableView.showsVerticalScrollIndicator=NO;
        _myreadTableView.bounces=NO;
        _myreadTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _myreadTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    }
    return _myreadTableView;
}
- (UITableView *)myFinshTableView
{
    if (_myFinshTableView==nil) {
        
        _myFinshTableView=[[UITableView alloc]initWithFrame:CGRectMake(SCREENWIDTH*2, 0, SCREENWIDTH, _scroll.frame.size.height) style:UITableViewStylePlain];
        _myFinshTableView.delegate=self;
        _myFinshTableView.dataSource=self;
        _myFinshTableView.showsVerticalScrollIndicator=NO;
        _myFinshTableView.bounces=NO;
        _myFinshTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _myFinshTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    }
    return _myFinshTableView;
}

- (id)init
{
    self = [super init];
    if (self) {
        
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    if (isread == 1) {
        
        self.scroll.contentOffset = CGPointMake(SCREENWIDTH, 0);
        
    }else if (isread == 3)
    {
        self.scroll.contentOffset = CGPointMake(SCREENWIDTH*2, 0);
    }else
    {
        self.scroll.contentOffset = CGPointMake(0, 0);
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.navBar.nav_titleLabel.text=@"作业统计";
    stateQuanXuan=@"1";
    dataArray=[NSMutableArray array];
    rdataArray=[NSMutableArray array];
    finshArray=[NSMutableArray array];
    xuanzhongArray=[NSMutableArray array];
    
    flag=YES;
    isread=2;
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = backItem;
    allNum=@"0";
    noreadNum=@"0";
    readNum=@"0";
    
    [self loadTopView];
    
    [self loadTableView];
    
    [self requestReadData];
    
    [self requestFinshData];
    
    [self requestData];
    
//    [self initAllReadView];
//    
//    [self initNoReadView];
//    
//    [self initNoFinshView];
  
    
    
            // Do any additional setup after loading the view.
}
-(void)loadTableView
{

    [self.scroll addSubview:self.myTableView];
    
    noemptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake((SCREENWIDTH-120)/2, (self.scroll.frame.size.height-110)/2-70, 120, 110) andBackImage:@"participationlist_empty" andBottomStr:@"全体宝宝已读"];
    [_myTableView addSubview:noemptyView];
    
    if (_model.smssum>0) {
        sendMesImage=[[UIImageView alloc]initWithFrame:CGRectMake(12,self.scroll.frame.size.height-20-38-10-27, 15, 15)];
        sendMesImage.image=[UIImage imageNamed:@"choose_message_nor_"];
        isSend=NO;
        [self.scroll addSubview:sendMesImage];
        
        sendLale=[[UILabel alloc]initWithFrame:CGRectMake(sendMesImage.frame.origin.x+sendMesImage.frame.size.width+15,sendMesImage.frame.origin.y, 200, 15)];
        sendLale.text=@"同时发送短信通知";
        sendLale.font=[UIFont systemFontOfSize:15];
        sendLale.textColor=RGBACOLOR(59, 59, 59, 1);
        [self.scroll addSubview:sendLale];
        
        sendMes=[UIButton buttonWithType:UIButtonTypeCustom];
        sendMes.frame=CGRectMake(12,self.scroll.frame.size.height-20-38-10-27, 240, 15);
        [sendMes addTarget:self action:@selector(sendMessageAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.scroll addSubview:sendMes];
    }
    allSelectBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    allSelectBtn.frame=CGRectMake(SCREENWIDTH-64,self.scroll.frame.size.height-20-38-10-27, 52, 23);
    
    [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
    
    [allSelectBtn addTarget:self action:@selector(selectTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.scroll addSubview:allSelectBtn];
    
    
    sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame=CGRectMake(12, self.scroll.frame.size.height-20-38, [UIScreen mainScreen].bounds.size.width-24, 38);
    sureBtn.layer.cornerRadius=5;
    [sureBtn setTitle:@"再次通知" forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(secondHomeAction:) forControlEvents:UIControlEventTouchUpInside];
    [sureBtn setBackgroundColor:RGBACOLOR(0, 180, 255, 1)];
    [self.scroll addSubview:sureBtn];

    [self.scroll addSubview:self.myreadTableView];
    
    reademptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake((SCREENWIDTH-120)/2, (self.scroll.frame.size.height-110)/2-70, 120, 110) andBackImage:@"participationlist_empty" andBottomStr:@"全体宝宝未读"];
    [_myreadTableView addSubview:reademptyView];
    
    [self.scroll addSubview:self.myFinshTableView];
    finishemptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake(0, (self.scroll.frame.size.height-110)/2-70, SCREENWIDTH, 110) andBackImage:@"participationlist_empty" andBottomStr:@"暂无宝宝完成"];
    [_myFinshTableView addSubview:finishemptyView];
    
    [self.view addSubview:self.scroll];
    
}

-(void)loadTopView
{
    UIView *back=[[UIView alloc]initWithFrame:CGRectMake(0,64, [UIScreen mainScreen].bounds.size.width, 168)];
    
    UIView *view01=[[UIView alloc]initWithFrame:CGRectMake(0, 0, back.frame.size.width, 105)];
    UILabel *courseLabel=[[UILabel alloc]initWithFrame:CGRectMake(12, 9, 150, 17)];
    courseLabel.text=[NSString stringWithFormat:@"%@作业",_model.coursename];
    courseLabel.font=[UIFont boldSystemFontOfSize:17];
    courseLabel.textColor=RGBACOLOR(59, 59, 59, 1);
    [view01 addSubview:courseLabel];
    
//    UILabel *weakLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-12-38, 9, 38, 11)];
//    weakLabel.text=_model.week;
//    weakLabel.textAlignment=NSTextAlignmentRight;
//    weakLabel.font=[UIFont systemFontOfSize:11];
//    weakLabel.textColor=RGBACOLOR(151, 151, 151, 1);
//    [view01 addSubview:weakLabel];
    
    UILabel *timelabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-12-100, 9, 100, 11)];
    timelabel.text=[Utils getDataStringWithoutSecondString:_model.jointime];
    timelabel.textAlignment=NSTextAlignmentRight;
    timelabel.font=[UIFont systemFontOfSize:11];
    timelabel.textColor=RGBACOLOR(151, 151, 151, 1);
    [view01 addSubview:timelabel];
    
    UILabel *ContentLabe=[[UILabel alloc]initWithFrame:CGRectMake(12, courseLabel.frame.origin.y+courseLabel.frame.size.height+11,SCREENWIDTH-24, 36)];
    if (_model.scontent.length==0) {
        ContentLabe.text=@"作业内容,请点击进入查看图片信息。";
    }
    else
    {
        ContentLabe.text=_model.scontent;
    }
    ContentLabe.font=[UIFont systemFontOfSize:15];
    ContentLabe.numberOfLines=2;
    ContentLabe.textColor=RGBACOLOR(59, 59, 59, 1);
    [view01 addSubview:ContentLabe];
    
    UILabel *sourceLabel=[[UILabel alloc]initWithFrame:CGRectMake(12, ContentLabe.frame.origin.y+ContentLabe.frame.size.height+11, SCREENWIDTH-24-52-18, 12)];
    sourceLabel.text=[NSString stringWithFormat:@"发送对象：%@",_model.tousername
                      ];
    sourceLabel.font=[UIFont systemFontOfSize:12];
    sourceLabel.textColor=RGBACOLOR(151, 151, 151, 1);
    [view01 addSubview:sourceLabel];
    
    UILabel *detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-12-52, sourceLabel.frame.origin.y, 60, 13)];
    detailLabel.text=@"查看详情";
    detailLabel.font=[UIFont systemFontOfSize:13];
    detailLabel.textAlignment=NSTextAlignmentRight;
    detailLabel.textColor=RGBACOLOR(56, 173, 255, 1);
    [view01 addSubview:detailLabel];
    
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, view01.frame.size.height-0.5, [UIScreen mainScreen].bounds.size.width,0.5)];
    line.backgroundColor=RGBACOLOR(199, 199, 204, 1);
    [view01 addSubview:line];
    
    UIView *view04=[[UIView alloc]initWithFrame:CGRectMake(0, view01.frame.origin.y+view01.frame.size.height, [UIScreen mainScreen].bounds.size.width, 10)];
    view04.backgroundColor=RGBACOLOR(239, 239, 244, 1);
    UIImageView *line2=[[UIImageView alloc]initWithFrame:CGRectMake(0, view04.frame.size.height-0.5, [UIScreen mainScreen].bounds.size.width,0.5)];
    line2.backgroundColor=RGBACOLOR(199, 199, 204, 1);
    [view04 addSubview:line2];
    
    
    UIView *view02=[[UIView alloc]initWithFrame:CGRectMake(0, view04.frame.origin.y+view04.frame.size.height, [UIScreen mainScreen].bounds.size.width, 54)];
    
    UIImageView *imageback=[[UIImageView alloc]initWithFrame:CGRectMake(60, 12, SCREENWIDTH-120, 30)];
    imageback.layer.borderWidth=1;
    imageback.layer.borderColor=RGBACOLOR(56, 173, 255, 1).CGColor;
    imageback.layer.cornerRadius=5;
    imageback.userInteractionEnabled=YES;
    
    
    noreadBtn=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, imageback.frame.size.width/3-1, 28)];
    [noreadBtn setTitle:[NSString stringWithFormat:@"未读(%@)",noreadNum] forState:UIControlStateNormal];
    [noreadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [noreadBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    [noreadBtn addTarget:self action:@selector(pushnoReadBtnList:) forControlEvents:UIControlEventTouchUpInside];
    noreadBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [imageback addSubview:noreadBtn];
    
    readBtn=[[UIButton alloc]initWithFrame:CGRectMake(imageback.frame.size.width/3, 0, imageback.frame.size.width/3, 30)];
    
    [readBtn setTitle:[NSString stringWithFormat:@"已读(%@)",readNum] forState:UIControlStateNormal];

    [readBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [readBtn addTarget:self action:@selector(pushReadList:) forControlEvents:UIControlEventTouchUpInside];
    readBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    readBtn.layer.borderWidth=1;
    readBtn.layer.borderColor=RGBACOLOR(57, 173, 255, 1).CGColor;
    
    [imageback addSubview:readBtn];
    
    
    finshBtn=[[UIButton alloc]initWithFrame:CGRectMake(imageback.frame.size.width/3*2, 1, imageback.frame.size.width/3-1, 28)];
    [finshBtn setTitle:[NSString stringWithFormat:@"已完成(%@)",finshNum] forState:UIControlStateNormal];
    [finshBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];

    [finshBtn addTarget:self action:@selector(pushFinshBtnList:) forControlEvents:UIControlEventTouchUpInside];
    finshBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [imageback addSubview:finshBtn];
    
    [view02 addSubview:imageback];

    view01.backgroundColor=[UIColor whiteColor];
    view02.backgroundColor=[UIColor whiteColor];
    
    UIButton *todetailBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    todetailBtn.frame=CGRectMake(0, 0, back.frame.size.width,105);
    [todetailBtn addTarget:self action:@selector(todetailVC2:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [view01 addSubview:line];
    [back addSubview:view01];
    [back addSubview:view02];
    [back addSubview:view04];
    [back addSubview:todetailBtn];
    [self.view addSubview:back];
}
-(void)sendMessageAction:(UIButton *)sender
{
    isSend=!isSend;
    if (isSend) {
        sendMesImage.image=[UIImage imageNamed:@"choose_message_press_"];
    }else
    {
        sendMesImage.image=[UIImage imageNamed:@"choose_message_nor_"];
    }
}
-(void)secondHomeAction:(UIButton *)sender
{
    NSMutableArray *XIDArray=[NSMutableArray array];
    for (int i=0; i<[dataArray count]; i++) {
        noReadModel *model=[dataArray objectAtIndex:i];
        if (model.check) {
            [XIDArray addObject:[NSString stringWithFormat:@"%ld",(long)model.studentid]];
        }
    }
    NSString *gouxuanStr=[XIDArray componentsJoinedByString:@","];
    if (XIDArray.count==0) {
        [Utils alertViewWithMessage:@"请选择宝宝！"];
        return;
    }

    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"sy_info_remindagain" forKey:@"method"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:gouxuanStr forKey:@"students"];
    if (isSend==YES) {
    [dict setObject:gouxuanStr forKey:@"sendsmsstudents"];
    }
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        NSDictionary *remindagaindic = (NSDictionary *)resposeJson;
       [Utils alertViewWithMessage:[remindagaindic objectForKey:@"re_info"]];
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}
-(void)requestData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_noreadlist" forKey:@"method"];
    [dict setObject:@"200" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:@"0" forKey:@"studentid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->Infodict = (NSDictionary *)resposeJson;
        self->noreadNum=[self->Infodict objectForKey:@"re_noreadnum"];
        [self->noreadBtn setTitle:[NSString stringWithFormat:@"未读(%@)",self->noreadNum] forState:UIControlStateNormal];

        NSArray * array = [self->Infodict objectForKey:@"re_data"];
        [self->dataArray removeAllObjects];
        
        if (array.count>0) {
        self->sureBtn.hidden=NO;
        self->allSelectBtn.hidden=NO;
//        [self->allreadworkView removeFromSuperview];
        [self->noemptyView hideEmptyImage];
            
            for (NSDictionary *dic in array) {
                noReadModel *model=[noReadModel mj_objectWithKeyValues:dic];
                model.check=YES;
                [self->dataArray addObject:model];
            }
        
          self->count=(int)self->dataArray.count;
          self->_myTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
            
        }else
        {
            self->sureBtn.hidden=YES;
            self->allSelectBtn.hidden=YES;
            if (self->_model.smssum>0) {
                self->sendMesImage.hidden=YES;
                self->sendLale.hidden=YES;
                self->sendMes.hidden=YES;
            }
            
            self->_myTableView.backgroundColor=[UIColor whiteColor];
//            [self->_myTableView addSubview:self->allreadworkView];
            [self->noemptyView showEmptyImage];
        }
        
        [self->_myTableView reloadData];
        
    } failure:^(NSInteger recode, NSError * error){
        
        [self showHint:@"网络异常,请稍后重试!"];
    }];
    
}
-(void)requestReadData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_readlist" forKey:@"method"];
    [dict setObject:@"200" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:@"0" forKey:@"studentid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->rInfodict = (NSDictionary *)resposeJson;
        self->readNum=[self->rInfodict objectForKey:@"re_readnum"];
        [self->readBtn setTitle:[NSString stringWithFormat:@"已读(%@)",self->readNum]  forState:UIControlStateNormal];
        NSArray * array = [self->rInfodict objectForKey:@"re_data"];
        
        [self->rdataArray removeAllObjects];
        
        if (array.count>0) {
            
//        [self->noworkView removeFromSuperview];
            
        [self->reademptyView hideEmptyImage];
            
        for (NSDictionary *dic in array) {
            noReadModel *model=[noReadModel mj_objectWithKeyValues:dic];
            model.check=YES;
            [self->rdataArray addObject:model];
        }
            
            self->_myreadTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
        }else
        {
            
            self->_myreadTableView.backgroundColor=[UIColor whiteColor];
//            [self->_myreadTableView addSubview:self->noworkView];
            [self->reademptyView showEmptyImage];
        }
        
        [self->_myreadTableView reloadData];
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}

- (void) requestFinshData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_finishlist" forKey:@"method"];
    [dict setObject:@"200" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:@"0" forKey:@"studentid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->finshInfoDic = (NSDictionary *)resposeJson;
        self->finshNum=[self->finshInfoDic objectForKey:@"re_finishnum"];
        
        [self->finshBtn setTitle:[NSString stringWithFormat:@"已完成(%@)",self->finshNum]  forState:UIControlStateNormal];
        NSArray * array = [self->finshInfoDic objectForKey:@"re_data"];
        
        [self->finshArray removeAllObjects];
        
        if (array.count>0) {
            
            [self->finishemptyView hideEmptyImage];
            
            for (NSDictionary *dic in array) {
                noReadModel *model=[noReadModel mj_objectWithKeyValues:dic];
                model.check=YES;
                [self->finshArray addObject:model];
            }
            self->_myFinshTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
        }else
        {
            
            self->_myFinshTableView.backgroundColor=[UIColor whiteColor];

            [self->finishemptyView showEmptyImage];
        }
        
        [self->_myFinshTableView reloadData];
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];

}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView==_myTableView) {
        
        return [dataArray count];
        
    } else if(tableView==_myreadTableView)
    {
        return  [rdataArray count];
    }else
    {
        return [finshArray count];
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{
    return 44;
}
-(void)todetailVC2:(UIButton *)sender
{
    DetailHvkViewController *view=[[DetailHvkViewController alloc]init];
    view.model=_model;
    [self.navigationController pushViewController:view animated:YES];
}
-(void)selectTouchAction:(UIButton *)sender
{
    //flag=yes 未全选；=no为全部取消
    //全选
    flag=!flag;
    if (flag==YES) {
        [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
        count=(int)dataArray.count;
        if (dataArray.count>0) {
            for ( int i=0;i<dataArray.count;i++) {
                noReadModel *model=[dataArray objectAtIndex:i];
                model.check=YES;
                [dataArray replaceObjectAtIndex:i withObject:model];
            }
        }
        
    }else
    {
        [allSelectBtn setImage:[UIImage imageNamed:@"all_choose_"] forState:UIControlStateNormal];
        count=0;
        for ( int i=0;i<dataArray.count;i++) {
            noReadModel *model=[dataArray objectAtIndex:i];
            model.check=NO;
            [dataArray replaceObjectAtIndex:i withObject:model];
        }
    }
    [_myTableView reloadData];
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIndentifier=@"cell";
    
    noReadListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    
    if (cell==nil) {
     cell = [[noReadListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
        
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消选择状态
    cell.index=indexPath;
    
    if (isread==2) {
        noReadModel *model=[dataArray objectAtIndex:indexPath.row];
        NSString *  nameStr=model.studentname;

        cell.nameLabel.text=nameStr;
        if (![model.logo hasPrefix:@"http"]&&model.logo!=nil) {
           NSString * logo = [REQUESTIMAGEURL stringByAppendingString:model.logo];
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        }
       

        
        cell.selectBtn.tag=indexPath.row+100;
        cell.selectBtn.userInteractionEnabled=YES;
        if (model.check) {
            cell.selectImage.hidden=NO;
            cell.selectBtn.enabled=YES;
            cell.selectImage.image=[UIImage imageNamed:@"homeworks_allchoose_press_"];
        }
        else
        {
            cell.selectImage.hidden=NO;
            cell.selectBtn.enabled=YES;
            cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_nor_"];
        }
        
        cell.line.hidden=NO;
        cell.lLine.hidden=YES;
        if (indexPath.row==([dataArray count]-1)) {
            cell.line.hidden=YES;
            cell.lLine.hidden=NO;
        }
        [cell.selectBtn addTarget:self action:@selector(dianjiTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }else
    {
        noReadModel *model;
        if (isread==1) {
            model=[rdataArray objectAtIndex:indexPath.row];
        }else
        {
            model=[finshArray objectAtIndex:indexPath.row];
        }
        
        NSString *  nameStr=model.studentname;
        if (isread==3) {
            UILabel *timelabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-100-12, 16, 100, 12)];
            timelabel.font=[UIFont systemFontOfSize:12];
            timelabel.textColor=RGBACOLOR(151, 151, 151, 1);
            timelabel.textAlignment=NSTextAlignmentRight;
            timelabel.text=[Utils getDataStringWithString:model.finishtime];
            [cell.contentView addSubview:timelabel];
        }
        cell.nameLabel.text=nameStr;
        
        if (![model.logo hasPrefix:@"http"]&&model.logo!=nil) {
            NSString * logo = [REQUESTIMAGEURL stringByAppendingString:model.logo];
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        }
        
        
        cell.selectImage.hidden=YES;
        cell.selectBtn.enabled=NO;
        
        cell.line.hidden=NO;
        cell.lLine.hidden=YES;
        
        if (isread==1) {
            if (indexPath.row==([rdataArray count]-1)) {
                cell.line.hidden=YES;
                cell.lLine.hidden=NO;
            }
        }else
        {
            if (indexPath.row==([finshArray count]-1)) {
                cell.line.hidden=YES;
                cell.lLine.hidden=NO;
            }
        }

    }

    return cell;
}
-(void)dianjiTouchAction:(UIButton *)sender
{
    
    noReadListViewCell *cell=[_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag-100 inSection:0]];//获取当前点击cell
    int row=(int)(sender.tag-100);
    noReadModel *model=[dataArray objectAtIndex:row];
    model.check=!model.check;
    if (!model.check) {
        count--;
        [dataArray replaceObjectAtIndex:row withObject:model];
        [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_"] forState:UIControlStateNormal];
        flag=NO;
        
        
    }else
    {
        count++;
        [dataArray replaceObjectAtIndex:row withObject:model];
        if (count==[dataArray count]) {
            [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
            flag=YES;
        }
    }
    if (model.check) {
        cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_press_"];
    }else
    {
        cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_nor_"];
    }

}

-(void)initAllReadView{
    

    allreadworkView = [[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH-185)/2, (self.scroll.frame.size.height-185)/2, 185, 185)];

    allreadworkView.backgroundColor = [UIColor clearColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn sizeToFit];
    btn.frame = CGRectMake(0, 0, 185, 185);
    [btn setImage:[UIImage imageNamed:@"all_read_"] forState:UIControlStateNormal];
    btn.enabled = NO;
    [allreadworkView addSubview:btn];
    
}

-(void) initNoReadView
{
    noworkView = [[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH-185)/2, (self.scroll.frame.size.height-185)/2 , 185,185)];
    noworkView.backgroundColor = [UIColor clearColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn sizeToFit];
    btn.frame = CGRectMake(0, 0, 185, 185);

    [btn setImage:[UIImage imageNamed:@"no_read_"] forState:UIControlStateNormal];
    btn.enabled = NO;
    [noworkView addSubview:btn];
}
-(void) initNoFinshView
{
    noFinshView = [[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH-185)/2, (self.scroll.frame.size.height-185)/2 , 185,185)];
    noFinshView.backgroundColor = [UIColor clearColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn sizeToFit];
    btn.frame = CGRectMake(0, 0, 185, 185);
    
    [btn setImage:[UIImage imageNamed:@"zanwu_wanchengzuoye_"] forState:UIControlStateNormal];
    btn.enabled = NO;
    [noFinshView addSubview:btn];
}
-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)pushReadList:(UIButton *)sender
{
    self.scroll.contentOffset=CGPointMake(SCREENWIDTH, 0);
   
   [readBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
   [readBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    
   [noreadBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
   [noreadBtn setBackgroundColor:[UIColor clearColor]];
    
    [finshBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [finshBtn setBackgroundColor:[UIColor clearColor]];

    if (isread!=1) {
       
        [self requestReadData];
    }
    
    isread=1;
    
    
}
-(void)pushnoReadBtnList:(UIButton *)sender
{
   self.scroll.contentOffset=CGPointMake(0, 0);
    
  [noreadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  [noreadBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    
  flag = YES;
  [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
    
  [readBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
  [readBtn setBackgroundColor:[UIColor clearColor]];
    
    [finshBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [finshBtn setBackgroundColor:[UIColor clearColor]];

    if (isread!=2) {
        
       [self requestData];
    }
       isread=2;
    
    
  
}
-(void)pushFinshBtnList:(UIButton *)sender
{
    self.scroll.contentOffset=CGPointMake(SCREENWIDTH*2, 0);
    
    [finshBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [finshBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    
    [readBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [readBtn setBackgroundColor:[UIColor clearColor]];
    
    [noreadBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [noreadBtn setBackgroundColor:[UIColor clearColor]];
    
    if (isread!=3) {
        
        [self requestFinshData];
    }
    isread=3;
    

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
